using UnityEngine;
using System;

namespace Math
{
    public static class Maths
    {
        public static int Abs(int i)
        {
            return (i>0)?i:-i;
        }

        public static float Abs(float f)
        {
            return (f>0.0f)?f:-f;
        }

        public static int Min(int a, int b)
        {
            return (a<=b)?a:b;
        }

        public static int Max(int a, int b)
        {
            return (a>=b)?a:b;
        }

        public static int Floor(float f)
        {
            return (int)Mathf.Floor(f);
        }

        public static int Round(float f)
        {
            return Floor(f+0.5f);
        }

        public static int Clamp(int i, int min, int max)
        {
            return (i>max)?max:((i<min)?min:i);
        }

        public static float Clamp(float f, float min, float max)
        {
            return (f>max)?max:((f<min)?min:f);
        }

        public static float ClampAngle(float d, float min, float max)
        {
            if (d<-360.0f) d += 360.0f;
            else if (d>360.0f) d -= 360.0f;
            return Clamp(d, min, max);
        }

        public static void GetIntegerAndFractional(float r, out int i, out float f)
        {
            i = Floor(r);
            f = r-i;
        }
    }
}